// JavaScript Document
(function(window){
	function Player($audio){
		return new Player.prototype.init($audio);
		}
	Player.prototype={
		construstor:Player,
		contentList:[],
		init:function($audio){
			this.$audio=$audio;
			this.audio =$audio.get(0); 
				},

				currentIndex:-1,
				//删除音乐
		changeMusic:function(index){
		  this.contentList.splice(index,1);
		 //判断删除是否是当前播放歌曲的前一首
		 if(index < this.currentIndex){
			 this.currentIndex=this.currentIndex-1;
			 }
			
			},
	lastIndex:function(){
		var index = this.currentIndex-1;
		if(index<0){
			index = this.contentList.length-1;
			
			}
		  return index;
		},
	
	nextIndex:function(){
		var index = this.currentIndex+1;
		if(index>this.contentList.length-1){
			index = 0;
			}
		  return index;
		},
			playMusic:function(index,music){
				//判断是否是当前音乐
				if(this.currentIndex==index){
					//同一首
					if(this.audio.paused){
						this.audio.play();
						}else{		
							this.audio.pause();
							}
					}else{
						//不是同一首
						this.$audio.attr("src",music.link_url);
						this.audio.play();
						this.currentIndex= index;		
						}
				},
				// //当前播放时间
				// getMusicDuration:function(){
				// 	return this.audio.duration;
				//
				// 	},
				// //歌曲总时长
				// getMusicCurrentTime:function(){
				// 	return this.audio.currentTime;
				//
				// 	},
				// //跳转到规定时间
				musicSeekTo:function(value){
					/*if(isNaN(value)) return;*/
					this.audio.currentTime = this.audio.duration*value;
					
					},
				 //控制声音开关闭
				 musicVioceSeekTo:function(value){
					if(isNaN(value)) return;
					if(value<0 || value>100) return;
					 this.audio.volume=value;
					 } 	,
				getMusicTimeUpDate:function(callBack){
				  var $this=this;
				  $this.$audio.on("timeupdate",function(){
				 var duration=$this.audio.duration;
				 var currentTime=$this.audio.currentTime;
				 
				 var timestr=$this.fromatime(currentTime,duration);
		              callBack(currentTime,duration,timestr);
		            });
				},
			fromatime:function(currentTime,duration){	
				  //转化时间格式
				 var endMin = parseInt(duration/60);
				 var endSec =parseInt(duration%60);
				  var startMin = parseInt(currentTime/60);
				 var startSec =parseInt(currentTime%60);
				 if(endMin<10){
					 endMin="0"+endMin;
					 }
				if(endSec<10){
					endSec="0"+endSec;
					}
				  if(startMin<10){
					 startMin="0"+startMin;
					 }
				if(startSec<10){
					startSec="0"+startSec;
					}
				return startMin+":"+startSec+"/" +endMin+":"+endSec;
				
				 },
   }
	 
		
	Player.prototype.init.prototype =Player.prototype;
	window.Player=Player;
	
	
	
	}(window))